using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;

public class EditorUtilityTest_Other
{
    [MenuItem("EditorUtilityTest/Parent/Set")]
    public static void SetParent()
    {
        var parent = GameObject.Find("Parent");
        EditorUtility.SetDefaultParentObject(parent);
    }

    [MenuItem("EditorUtilityTest/Parent/Clear")]
    public static void ClearParent()
    {
        EditorUtility.ClearDefaultParentObject();
    }

    [MenuItem("Assets/OpenPropertyEditor")]
    public static void OpenPropertyEditor()
    {
        EditorUtility.OpenPropertyEditor(Selection.objects[0]);
    }

    [MenuItem("EditorUtilityTest/Other/FocusProjectWindow")]
    public static void FocusProjectWindow()
    {
        EditorUtility.FocusProjectWindow();
    }

    [MenuItem("Assets/EditorUtilityTest/CollectDependencies")]
    public static void CollectDependencies()
    {
        //var objs = EditorUtility.CollectDependencies(Selection.objects);
        var objs = Selection.objects;//EditorUtility.CollectDependencies(Selection.objects);
        for (int i = 0; i < objs.Length; i++)
        {
            var texture = objs[i] as Texture2D;
            EditorUtility.CompressTexture(texture, TextureFormat.Alpha8, 1);
            EditorUtility.SetDirty(texture);
        }
        AssetDatabase.SaveAssets();
        AssetDatabase.Refresh();
    }
}

public class CompressTextureExample : AssetPostprocessor
{
    // Automatically Compress all imported textures to the project to RGB24
    void OnPostprocessTexture(Texture2D t)
    {
        EditorUtility.CompressTexture(t, TextureFormat.RGB24, TextureCompressionQuality.Normal);
    }
}
